package com.example.yichuangyun.mvvm.ui.fragment;

import android.os.Bundle;

import com.example.yichuangyun.R;
import com.example.yichuangyun.config.Constant;
import com.example.yichuangyun.databinding.FragmentBusinessRecordBinding;
import com.example.yichuangyun.mvvm.base.BaseFragment;
import com.example.yichuangyun.mvvm.ui.activity.order.view.OrderDetailsViewModel;
import com.example.yichuangyun.mvvm.ui.adapter.OrderBusinessAdapter;

/**
 * 订单详情-商机
 */
public class OrderBusinessFragment extends BaseFragment<FragmentBusinessRecordBinding, OrderDetailsViewModel> {

    private OrderBusinessAdapter adapter;

    @Override
    protected OrderDetailsViewModel bindModel() {
        return getViewModel(this, OrderDetailsViewModel.class);
    }

    @Override
    protected void initInject() {
        getFragmentComponent().inject(this);
    }

    @Override
    public void initData() {
        adapter = new OrderBusinessAdapter();
        binding.recyclerView.setAdapter(adapter);
        adapter.setEmptyViewEnable(true);
        adapter.setEmptyViewLayout(mContext, R.layout.layout_empty_list2);
    }

    @Override
    protected void lazyLoadData() {
        Bundle bundle = getArguments();
        if (bundle != null) {
            String businessId = bundle.getString(Constant.businessIdKey);
            viewModel.getOrderDetailsForBusiness(businessId);
        }
    }

    @Override
    protected void initClick() {
        viewModel.businessListMutableLiveData.observe(this, businessModels -> adapter.submitList(businessModels));
    }

    public static OrderBusinessFragment newInstance(String businessId) {
        Bundle bundle = new Bundle();
        bundle.putString(Constant.businessIdKey, businessId);
        OrderBusinessFragment fragment = new OrderBusinessFragment();
        fragment.setArguments(bundle);
        return fragment;
    }
}
